package cn.wechat.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import cn.wechat.pojo.user.Goods;
import cn.wechat.service.goods.GoodsService;
import cn.wechat.tools.Constants;

@Controller
@RequestMapping(value="/goods")
public class GoodsController {
	@Resource(name = "goodsService")
	public GoodsService goodsService;

	/**
	 * 查询物品，通过商品和商家进行模糊查询 跳转到search.jsp
	 * 
	 * @param model
	 * @param goodsName
	 * @param goodsoBrand
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/find.html")
	public String find(
			Model model,
			@RequestParam(value = "goodsName", required = false) String goodsName,
			@RequestParam(value = "goodsoBrand", required = false) String goodsoBrand)
			throws Exception {
		List<Goods> goods = null;
		if (goodsName == null) {
			goodsName = "";
		}
		if (goodsoBrand == null) {
			goodsoBrand = "";
		}
		goods = goodsService.look(goodsName, goodsoBrand);

		model.addAttribute("goods", goods);
		model.addAttribute("goodsName", goodsName);
		model.addAttribute("goodsoBrand", goodsoBrand);

		return "find";
	}

	/**
	 * 显示商品数据在index界面
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/findAll.html")
	public String findAll(Model model) {
		List<Goods> goodsList = goodsService.getAll();
		System.out.println("111111");
		if (null!=goodsList) {
			model.addAttribute("goodsList", goodsList);
		} else {
			System.out.println("错误！");
		}
		return "findAll";
	}
}
